/*
* @Author: JINPENG
* @Date:   2018-08-08 20:30:46
* @Last Modified by:   JINPENG
* @Last Modified time: 2018-08-08 21:53:46
*/
'use strict'
require('./index.css');
require('page/common/nav/index.js');
require('page/common/header/index.js');
var _mm             = require('util/mm.js');
var _payment          = require('service/payment-service.js');
var templateIndex   = require('./index.string');

var page = {
    data : {
        orderNumber : _mm.getUrlParam('orderNumber')
    },
     init: function(){
        this.onLoad();
    },
    onLoad : function(){
        this.loadPayment();
    },
    //加载订单列表
    loadPayment : function(){
        var _this       =   this,
        orderPaymentHtml =   '',
        $pageWrap = $('.page-wrap');
         $pageWrap.html('<div class="loading"></div>');
        _payment.getOrderPayment(this.data.orderNumber,function(res){
            //渲染Html
            orderPaymentHtml = _mm.renderHtml(templateIndex,res);
            $pageWrap.html(orderPaymentHtml);
            _this.listenOrderStatus();
        },function(errMsg){
            $pageWrap.html('<p class="err-tip">+ errMsg +</p>');
        });
    },
    listenOrderStatus : function(){
    var _this = this;
        this.paymentTimer = window.setInterval(function(){
        _payment.getpaymetStatus(_this.data.orderNumber,function(res){
            if (res === true) {
                window.location.href = '/result.html?type=payment&orderNumber='+_this.data.orderNumber;
                }
            });
        },5e3);
   }
};
$(function(){
    page.init();
});